home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * File: Editor.c
- *
- * Package: Mainline
- *
- * Description: This is the mainline for the editor program to test the
- * Inter Application Communications (IAC) driver. Some code
- * from the Apple "sample.c" was adapted.
- *
- * Structure: In this source the following structure is used:
- * includes & defines
- * global variable definitions
- * main()
- * initialization routines
- * the menu dispatcher menu_tree()
- * dialog-box handlers
- *
- * Author:
- * FEA 6/88 - 7/88
- */
-
- # include <types.h>
- # include <memory.h>
- # include <quickdraw.h>
- # include <toolutils.h>
- # include <windows.h>
- # include <controls.h>
- # include <fonts.h>
- # include <events.h>
- # include <dialogs.h>
- # include <menus.h>
- # include <desk.h>
- # include <textedit.h>
- # include <segload.h>
- # include <string.h>
- # include <resources.h>
-
- # include <iac.h>
- # undef PUBLIC
- # include <Editor.h>
-
- #define noErr 0 /* 0 for success */
-
- extern _DataInit();
-
-
- /**
- * Routine: main()
- *
- * Mainline of the test program
- */
-
- int main()
- {
- short init_result; /* NULL if OK */
- short item; /* alert button */
- Rect screenRect;
- Rect dragRect;
- Rect txRect;
- Point mousePt;
- EventRecord myEvent;
- WindowPtr theActiveWindow;
- WindowPtr whichWindow;
-
- win_dataH the_data_H; /* data associated with a window */
-
-
- extern void menu_tree(), do_key(), poll_iac();
- extern void ext_move();
- extern short edit_init();
- extern WindowPtr myWindow;
-
- UnloadSeg(_DataInit);
- init_result = edit_init();
- if (init_result)
- {
- item = StopAlert(NO_IAC, nil);
- return 0; /* allow C runtime cleanup */
- }
-
- UnloadSeg(edit_init); /* if we get here, IAC open */
-
- /* basic window setup is handled by 'new' and 'open' commands */
- screenRect = qd.screenBits.bounds;
- SetRect(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
-
- /* The One True Event Loop */
- DoneFlag = false;
- for ( ;; )
- {
- if (DoneFlag)
- {
- break; /* from main event loop */
- }
-
- /*
- * Main Event tasks:
- */
-
- theActiveWindow = FrontWindow(); /* Used often, avoid repeated calls */
-
- if (myWindow && (myWindow == theActiveWindow))
- {
- GetMouse(&mousePt);
- SetCursor(PtInRect(&mousePt, &myWindow->portRect) ? *ibeamHdl : &qd.arrow);
- TEIdle(TextH);
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- if ((**the_data_H).dirty)
- {
- EnableItem (MyMenus[fileMenu], saveCommand);
- }
- else
- {
- DisableItem (MyMenus[fileMenu], saveCommand);
- }
- }
-
- if (!WaitNextEvent(everyEvent, &myEvent, SLEEP, nil))
- {
- /* A null or system event! Here is the place for IAC polling.
- We only poll if we have link targets to check. */
- if (theActiveWindow && extent_count)
- {
- poll_iac(theActiveWindow);
- }
- continue;
- }
-
- the_data_H = (win_dataH) GetWRefCon(theActiveWindow);
- TextH = (**the_data_H).wind_TEH;
-
- switch (myEvent.what)
- {
- case mouseDown:
- switch (FindWindow(&myEvent.where, &whichWindow))
- {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
-
- case inMenuBar:
- menu_tree(MenuSelect(&myEvent.where));
- break;
-
- case inDrag:
- DragWindow(whichWindow, &myEvent.where, &dragRect);
- break;
-
- case inGrow: /* There is no grow box. */
- break;
-
- case inContent:
- if (whichWindow != theActiveWindow)
- {
- SelectWindow(whichWindow);
- }
- else if (whichWindow == myWindow)
- {
- ext_move(&myEvent, theActiveWindow);
- }
- break;
-
- default:
- break;
- }/*endsw FindWindow*/
- break;
-
- case autoKey: /* ignore command-key */
- if (myWindow == theActiveWindow)
- {
- do_key(myEvent.message); /* this lets us check extents */
- }
- break;
-
- case keyDown:
- if (myWindow == theActiveWindow)
- {
- if (myEvent.modifiers & cmdKey)
- {
- menu_tree(MenuKey(myEvent.message & charCodeMask));
- }
- else
- {
- do_key(myEvent.message); /* this lets us check extents */
- }
- }
- break;
-
- case app4Evt: /* suspend/resume */
- break;
-
- case activateEvt:
- if ((WindowPtr) myEvent.message == myWindow)
- {
- if (myEvent.modifiers & activeFlag)
- {
- TEActivate(TextH);
- DisableItem(MyMenus[editMenu], undoCommand);
- }
- else
- {
- TEDeactivate(TextH);
- EnableItem(MyMenus[editMenu], undoCommand);
- }
- }
- break;
-
- case updateEvt:
- if ((WindowPtr) myEvent.message == theActiveWindow)
- {
- BeginUpdate(theActiveWindow);
- EraseRect(&theActiveWindow->portRect);
- TEUpdate(&theActiveWindow->portRect, TextH);
- EndUpdate(theActiveWindow);
- }
- break;
-
- default:
- break;
-
- } /* endsw myEvent.what */
-
- } /* for */
-
- if (myWindow)
- {
- /* shut down code, including "save changes?" */
- CloseWindow(myWindow);
- }
- return 0; /* Return from main() to allow C runtime cleanup */
- }
-
-
- /**
- * Routine: chk_extent
- *
- * This routine checks the selection range in the TE record to determine
- * if it intersects the current extent. If not, it checks the entire set of
- * extents to try and identify the extent it might intersect. If we are not
- * currently in an exent, the 'current extent' structure is filled with -1s
- * as is 'curr_ext_no'.
- */
-
- # define __SEG__ Main
- Boolean chk_extent(TextH, the_extH, ext_cnt)
- TEHandle TextH; /* The TextEdit record to check */
- extentH the_extH; /* handle to extent block */
- short ext_cnt; /* how many extents to process */
- {
- short strt, endd; /* range in TE record */
- short i; /* scratch */
- exTable ext_recs;
- Boolean left, right;
-
-
- if (ext_cnt)
- {
- strt = (**TextH).selStart;
- endd = (**TextH).selEnd;
- ext_recs = *the_extH;
-
- /* Check last extent used. If not in that, scan entire table.
- * We are affecting an extent if EITHER the start or end of the TE
- * selection falls between the start and end of the extent (inclusive).
- */
- left = (curr_ext.ext_strt <= strt) && (curr_ext.ext_end >= strt);
- right = (curr_ext.ext_strt <= endd) && (curr_ext.ext_end >= endd);
- if (left || right) /* overlap on either end */
- {
- return (true); /* existing info alright as is */
- }
- else /* switched, check all */
- {
- for (i=0; i<ext_cnt; i++)
- {
- left = (ext_recs[i].ext_strt <= strt) && (ext_recs[i].ext_end >= strt);
- right = (ext_recs[i].ext_strt <= endd) && (ext_recs[i].ext_end >= endd);
- if (left || right) /* this is now the current extent */
- {
- curr_ext.ext_strt = ext_recs[i].ext_strt;
- curr_ext.ext_end = ext_recs[i].ext_end;
- curr_ext.hat_check = ext_recs[i].hat_check;
- curr_ext.ed_level = ext_recs[i].ed_level;
- curr_ext_no = i;
- return (true);
- }
- } /* end for */
- } /* end else */
- } /* end there-are-extents */
-
- curr_ext.ext_strt = -1; /* not current in an extent */
- curr_ext.ext_end = -1;
- curr_ext.hat_check = -1;
- curr_ext.ed_level = -1;
- curr_ext_no = -1;
- return(false);
- }
-
-
- /**
- * Routine: ext_write
- *
- * This routine handles the mechanics of actually writing an extent's
- * data to the IAC driver.
- */
-
- # define __SEG__ Main
- short ext_write(TextH, strt, sz, the_doc, the_hatcheck, the_ed)
- TEHandle TextH; /* The TextEdit handle */
- short strt; /* position of 1st char to write */
- short sz; /* count of bytes */
- long the_doc; /* which doc */
- short the_hatcheck;
- short *the_ed;
- {
- short iac_code; /* result from IAC call */
- long data_size;
- Handle ext_data, t_base;
- long *l_ptr; /* recast to ease setting up hdr */
-
- # define HDR_SIZE 8
-
- ext_data = NewHandle (sz + HDR_SIZE);
- l_ptr = (long *)(*ext_data);
- *l_ptr = TXT_FMT;
- *(l_ptr+1) = (long) sz;
- t_base = (**TextH).hText;
- BlockMove (*t_base + strt, /* source */
- (*ext_data) + HDR_SIZE, /* dest */
- (long) sz);
- iac_code = iac_write_data(the_doc, the_hatcheck, the_ed, 1, ext_data);
- DisposHandle(ext_data);
- return (iac_code);
- }
-
-
- /**
- * Routine: ext_read
- *
- * This routine handles the mechanics of actually reading an extent's
- * data from the IAC driver. If successful the edition_level for the extent
- * is updated.
- */
-
- # define __SEG__ Main
- short ext_read(w_Ptr, the_ed, which)
- WindowPtr w_Ptr;
- short *the_ed; /* edition of the extent to read */
- short which; /* which extent (zero-based) */
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- TEHandle TextH; /* The TextEdit handle */
- exTable ext_recs; /* for walking extents for adjusting */
- long fmt_code; /* actual data format from IAC */
- long fmt_pref[3]; /* format prefs, descending desirability */
- long old_st, old_end; /* TE selection before poll */
- short delta; /* change in extent size */
- short an_ed, j; /* traditional loop counters */
- short data_size;
- Handle ext_data; /* Handle to data block */
-
- short iac_code = noErr; /* result from IAC call */
-
- the_data_H = (win_dataH) GetWRefCon(w_Ptr);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
-
- fmt_pref[0] = TXT_FMT;
- fmt_pref[1] = 0;
- HLock(the_extH);
- ext_recs = *the_extH;
- ext_data = NewHandle(0L);
- /* need memory test here */
-
- an_ed = *the_ed + 1;
- iac_code = iac_read_data(ext_recs[which].src_doc,
- (**the_data_H).the_slot,
- ext_recs[which].hat_check,
- &an_ed,
- &fmt_pref[0],
- &fmt_code,
- ext_data);
-
- if (iac_code == noErr)
- {
- ext_recs[which].ed_level = an_ed; /* update extent */
- *the_ed = an_ed; /* update caller */
- data_size = GetHandleSize(ext_data);
-
- delta = data_size - (ext_recs[which].ext_end -
- ext_recs[which].ext_strt);
-
- TESetSelect (ext_recs[which].ext_strt, /* select extent for TE */
- ext_recs[which].ext_end,
- TextH);
- TEDelete(TextH);
- HLock(ext_data);
- TEInsert(*ext_data, data_size, TextH); /* update text */
- HUnlock(ext_data);
-
- ext_recs[which].ext_end = ext_recs[which].ext_strt + data_size; /* update end (start unchanged) */
-
- if (delta) /* only update if there was a change */
- {
- /* offset each following extent by change in size of this extent */
- for (j=which+1; j<(**the_data_H).ext_cnt; j++)
- {
- ext_recs[j].ext_strt += delta;
- ext_recs[j].ext_end += delta;
- }
- }
- }
-
- HUnlock(the_extH);
- DisposHandle (ext_data); /* clean up */
- return (iac_code);
- }
-
-
- /**
- * Routine: ext_move
- *
- * This routine checks to see if we have left the "current extent". If
- * we have, we check to see if we are the source for that extent. If so,
- * the contents of that extent are written to the IAC driver. If we are
- * instead mousing INTO an extent, that becomes the current extent.
- */
-
- # define __SEG__ Main
- void ext_move(myEvent, w_Ptr)
- EventRecord *myEvent;
- WindowPtr w_Ptr;
- {
- EventRecord anEvent;
- short iac_code; /* result from IAC call */
- OSErr an_err;
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs; /* for updating old extent */
- TEHandle TextH; /* The TextEdit handle */
- short i, the_ed, old_ext_no;
- short data_size;
- extent old_ext; /* to check for change in extents */
- Handle ext_data, t_base;
- long *l_ptr; /* recast to ease setting up hdr */
-
- extern Boolean ext_active;
-
- extern Boolean chk_extent();
-
- #define HDR_SIZE 8
-
- the_data_H = (win_dataH) GetWRefCon(w_Ptr);
- TextH = (**the_data_H).wind_TEH;
- the_extH = (**the_data_H).the_extents;
- ext_recs = *the_extH;
- old_ext_no = curr_ext_no;
- anEvent = *myEvent; /* local copy for modification */
-
- GlobalToLocal(&anEvent.where);
- TEClick(&anEvent.where, (anEvent.modifiers & shiftKey) != 0, TextH);
-
- if (ext_active) /* we may need to write it's data to the IAC driver */
- {
- old_ext = curr_ext;
- the_ed = curr_ext.ed_level;
- ext_active = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
-
- if ((old_ext.ext_strt != curr_ext.ext_strt) ||
- !ext_active) /* we left the current extent */
- {
- if (curr_ext.src_doc==(**the_data_H).doc_ID) /* we were the source */
- {
- iac_code = ext_write(TextH,
- old_ext.ext_strt,
- (old_ext.ext_end - old_ext.ext_strt),
- (**the_data_H).doc_ID,
- old_ext.hat_check,
- &the_ed);
- ext_recs[old_ext_no].ed_level = the_ed; /* update old extent just written */
- }
- }
- }
- else /* see if we've moved into one! */
- {
- ext_active = chk_extent(TextH, the_extH, (**the_data_H).ext_cnt);
- /* Since we weren't in an extent, there's nothing to write */
- }
- }
-
-
- /**
- * Routine: ext_remove
- *
- * This routine severs a link in the drivers dependency table. It assumes
- * the driver will take care of removing any remaining data it sent.
- */
-
- # define __SEG__ Main
- void ext_remove(w_Ptr, extP)
- WindowPtr w_Ptr;
- extentP extP; /* extent to remove */
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- short iac_code; /* result from IAC call */
-
- the_data_H = (win_dataH) GetWRefCon (w_Ptr);
- iac_code = iac_remove_dependency((**the_data_H).doc_ID,
- (**the_data_H).the_slot,
- extP->hat_check);
- }
-
-
- /**
- * Routine: poll_iac
- *
- * This routine checks with the IAC driver to see if there's anything
- * to do. It checks at 1 second intervals to avoid excessive loading on
- * system capacity.
- *
- * In order to simplify management of the extent ranges, extents are stored
- * in ascending order by starting position. This means that updating an
- * extent involves adjusting the start/end of all SUCCEEDING extents by the
- * amount the updated extent changes, but no preceeding extents need be
- * touched. Storing the extents in random order is definitely a poor idea.
- */
-
- # define __SEG__ Main
- void poll_iac(w_Ptr)
- WindowPtr w_Ptr;
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs; /* for walking extents to read */
- TEHandle TextH; /* The TextEdit handle */
- short slot_ID, vers, the_ed; /* for IAC */
- long fmt_code; /* actual data format from IAC */
- long fmt_pref[3]; /* format prefs, descending desirability */
- long old_st, old_end; /* TE selection before poll */
- long my_docID; /* so I don't read my own extents! */
- short delta; /* change in extent size */
- short i,j; /* traditional loop counters */
- Handle ext_data; /* Handle to data block */
-
- short iac_code = noErr; /* result from IAC call */
- short waiting = 0; /* for IAC */
- short doc_count = 0; /* how many are open? */
-
- extern long last_poll; /* when we last polled IAC */
-
- if (TickCount() > (last_poll+POLL_INT)) /* minimum interval passed */
- {
- /* get relevent handles, etc */
- the_data_H = (win_dataH) GetWRefCon (w_Ptr);
- slot_ID = (**the_data_H).the_slot;
- the_extH = (**the_data_H).the_extents;
- TextH = (**the_data_H).wind_TEH;
- my_docID = (**the_data_H).doc_ID;
-
- iac_code = iac_status(slot_ID, &vers, &doc_count, &waiting);
-
- if (waiting>0) /* get data for each and update extents */
- {
- old_st = (**TextH).selStart; /* retain user's selection */
- old_end = (**TextH).selEnd;
- ext_recs = *the_extH; /* point to 1st extent */
- for (i=0; i<(**the_data_H).ext_cnt; i++)
- {
- if (my_docID != ext_recs[i].src_doc) /* don't read my own! */
- {
- the_ed = ext_recs[i].ed_level + 1; /* successor to last level read */
- iac_code = ext_read(w_Ptr, &the_ed, i);
-
- if (iac_code==noErr)
- {
- if ((waiting -= 1) == 0)
- {
- break; /* stop if no extents left to do */
- }
- }
- }
- } /* for */
-
- TESetSelect (old_st, old_end, TextH); /* restore original */
- }
-
- last_poll = TickCount(); /* update timer */
- }
- }
-
-
- /**
- * Routine: edit_init
- *
- * This handles all the grunt initialization.
- * It returns NULL if everything went OK, non-NULL if unable to open
- * the IAC driver or we aren't operating under MultiFinder.
- */
-
- # define __SEG__ init
- short edit_init()
- {
- short i, k, menu_limit;
- Str255 itemString;
-
- short result = 0; /* default optimism */
-
- extern MenuHandle MyMenus[];
- extern CursHandle ibeamHdl;
- extern long last_poll;
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- ibeamHdl = GetCursor(iBeamCursor);
- HNoPurge((Handle)ibeamHdl); /* ensure we keep it */
-
- result = iac_open(); /* try to get IAC driver */
- if (result != noErr) /* couldn't get it! */
- {
- NumToString ((long) result, &itemString);
- if (result==EARLY_SYS)
- {
- ParamText ("MultiFinder","",&itemString,"");
- }
- else
- {
- ParamText ("the IAC driver","",&itemString,"");
- }
- }
- else /* got it! */
- {
- ext_active = false; /* no "current extent" yet */
- curr_ext.hat_check = 0;
- curr_ext.ed_level = 0;
- curr_ext.ext_strt = 0;
- curr_ext.ext_end = 0;
-
- /* handle menu init'g (don't add link-display menu) */
- menu_limit = menuCount-1;
- for (i=appleMenu,k=appleID; i<menu_limit; i++,k++)
- {
- MyMenus[i] = GetMenu(k);
- }
- AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
- AddResMenu(MyMenus[fontMenu], (ResType) 'FONT');
- for (i=0; i<menu_limit ;++i )
- {
- InsertMenu(MyMenus[i],0);
- }
-
- /* set textstyling defaults */
- GetFNum ("Geneva", &the_fNum);
- the_size = 10;
- CheckItem (MyMenus[sizeMenu], 2, true);
- /* scan font menu to check default font */
- for (i=1; i<=CountMItems (MyMenus[fontMenu]); i++)
- {
- GetItem (MyMenus[fontMenu], i, &itemString);
- GetFNum (&itemString, &k);
- if (k==geneva)
- {
- CheckItem (MyMenus[fontMenu], i, true);
- break;
- }
- }
- DrawMenuBar(); /* now user can see menu bar */
- last_poll = TickCount(); /* so we can poll @ 1-sec intervals */
- }
-
- return(result);
- }
-
-
- /**
- * Routine: menu_tree
- *
- * This is the standard menu-processing tree.
- */
-
- # define __SEG__ Main
- void menu_tree(menu_sel)
- long menu_sel; /* menu/item selected */
- {
- short the_menu, the_item;
- GrafPtr savePort;
- char daName[256];
- Str255 itemString; /* font selection */
- short i;
- win_dataH the_data_H; /* data associated with a window */
- extentP extP; /* pointer to an extent to zap on quitting */
- TEHandle TextH; /* The TextEdit handle */
-
- extern short the_fNum, the_size; /* current attributes */
- extern Style the_style;
- extern MenuHandle MyMenus[];
- extern Boolean DoneFlag;
-
- extern void about_box();
- extern short open_doc(), create_doc(), close_doc(), save_doc();
- extern void do_clear(), do_copy(), do_cut(), do_paste();
- extern void do_hotCopy(), do_hotPaste(), killLink_box(), ext_remove();
- extern void link_display(), linkInfo_box();
-
-
- the_item = LOWORD(menu_sel);
- the_menu = HIWORD(menu_sel); /* This is the resource ID */
-
- if (myWindow)
- {
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- TextH = (**the_data_H).wind_TEH;
- }
-
- switch (the_menu)
- {
- case appleID:
- if (the_item == aboutMeCommand)
- {
- about_box();
- }
- else
- {
- GetItem(MyMenus[appleMenu], the_item, daName);
- GetPort(&savePort);
- (void) OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case fileID:
- switch (the_item)
- {
- case newCommand:
- (void) create_doc();
- break;
-
- case openCommand:
- (void) open_doc();
- break;
-
- case closeCommand:
- (void) close_doc();
- break;
-
- case saveCommand:
- (void) save_doc();
- break;
-
- case quitCommand:
- DoneFlag = true; /* I want out! */
- for (i=0; i<(**the_data_H).ext_cnt; i++)
- {
- extP = (*(**the_data_H).the_extents) +
- (i * sizeof(extent));
- ext_remove(myWindow, extP);
- }
- break;
-
- default:
- break;
- }
- break; /* fileID */
-
- case editID:
- switch (the_item)
- {
- case undoCommand: /* not implemented yet (if ever!) */
- break;
-
- case cutCommand:
- do_cut();
- break;
-
- case copyCommand:
- do_copy();
- break;
-
- case pasteCommand:
- do_paste();
- break;
-
- case clearCommand:
- do_clear();
- break;
-
- case hotCopyCommand:
- do_hotCopy();
- break;
-
- case hotPasteCommand:
- do_hotPaste();
- break;
-
- case zapLinkCommand:
- killLink_box();
- break;
-
- default:
- break;
- }
- break; /* editID */
-
- case optionsID:
- switch (the_item)
- {
- case showLinksCmd:
- break;
-
- case showLinkInfoCmd:
- linkInfo_box();
- break;
-
- default:
- break;
- }
- break; /* optionsID */
-
- case fontID:
- for (i=1; i<=CountMItems(MyMenus[fontMenu]); i++)
- {
- CheckItem (MyMenus[fontMenu], i, false); /* uncheck old font */
- }
- CheckItem (MyMenus[fontMenu], the_item, true);
- GetItem (MyMenus[fontMenu], the_item, &itemString);
- GetFNum (&itemString, &the_fNum);
- for (i=0; i<8; i++) /* set real sizes */
- {
- if (RealFont (the_fNum,f_sizes[i]))
- {
- SetItemStyle (MyMenus[sizeMenu], i+1, outline);
- }
- else
- {
- SetItemStyle (MyMenus[sizeMenu], i+1, normal);
- }
- }
- if (myWindow) /* force a refresh */
- {
- SetPort (myWindow);
- TextFont (the_fNum);
- (**TextH).txFont = the_fNum;
- TECalText (TextH);
- InvalRect (&myWindow->portRect);
- }
- break;
-
- case sizeID:
- if (the_item<9) /* setting new size */
- {
- for (i=1; i<9; i++) /* remove all checkmarks first */
- {
- CheckItem (MyMenus[sizeMenu], i, false);
- }
- the_size = f_sizes[the_item-1];
- CheckItem (MyMenus[sizeMenu], the_item, true);
- }
- else /* setting style */
- {
- if (the_style & f_styles[the_item-10]) /* already on? */
- {
- the_style &= (~f_styles[the_item-10]); /* turn off */
- CheckItem (MyMenus[sizeMenu], the_item, false);
- }
- else
- {
- the_style |= f_styles[the_item-10];
- CheckItem (MyMenus[sizeMenu], the_item, true);
- }
- }
- if (myWindow) /* force a refresh */
- {
- SetPort (myWindow);
- TextFace (the_style);
- TextSize (the_size);
- (**TextH).txFace = the_style;
- (**TextH).txSize = the_size;
- TECalText (TextH);
- InvalRect (&myWindow->portRect);
- }
- break;
-
- case linkDisplayID:
- link_display(the_item - 1); /* zero-based extent subscripts */
- break;
-
- default:
- break;
- } /* end switch(the_menu) */
-
- HiliteMenu(0);
-
- return;
- }
-
-
- /**
- * Routine: add_display_cmd()
- *
- * This is the routine that is called whenever a link is completed.
- * It adds a menu item to the "Links" menu so the user can highlight
- * any visible links in a distinctive fashion.
- */
-
- # define __SEG__ Main
- void add_display_cmd(which, total)
- short which; /* position in extent array */
- short total; /* total # of extents */
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs;
- Str255 num_str, cmd_str; /* for building menu item */
-
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- the_extH = (**the_data_H).the_extents;
- ext_recs = *the_extH;
-
- if ((**the_data_H).ext_cnt)
- {
- if (!link_menu) /* need to create link menu */
- {
- MyMenus[linkdDispMenu] = GetMenu(linkDisplayID);
- InsertMenu(MyMenus[linkdDispMenu],0);
- link_menu = true;
- }
-
- NumToString ((long) total, &num_str);
- if (ext_recs[which].src_doc == (**the_data_H).doc_ID)
- {
- strcpy(&cmd_str, "Source extent ");
- }
- else
- {
- strcpy(&cmd_str, "Target extent ");
- }
- (void) strcat(&cmd_str, &num_str); /* build complete menu item */
- AppendMenu (MyMenus[linkdDispMenu], &cmd_str);
-
- DrawMenuBar(); /* now user can see menu bar again */
- }
- }
-
- # define __SEG__ Main
- void link_display(ext_no)
- short ext_no; /* which extent to highlight */
- {
- win_dataH the_data_H; /* data associated with a window */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs; /* ptr to array of extents */
- short old_st, old_end; /* previous selection range */
- TEHandle TextH; /* The TextEdit handle */
-
- extern void SourceHigh(); /* assembler highlighting routine */
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- the_extH = (**the_data_H).the_extents;
- TextH = (**the_data_H).wind_TEH;
- ext_recs = *the_extH;
-
- old_st = (**TextH).selStart;
- old_end = (**TextH).selEnd;
-
- /* put a routine address into teHiHook for new highlighting routine */
- (**TextH).highHook = &SourceHigh();
- TESetSelect ((long) ext_recs[ext_no].ext_strt,
- (long) ext_recs[ext_no].ext_end,
- TextH);
-
- while (!Button()) ; /* wait for mouse-down */
- while (Button()) ; /* and following mouse-up */
-
- /* clear teHiHook to restore normal highlighting */
- TESetSelect ((long) old_st, (long) old_end, TextH); /* unhighligh extent */
- (**TextH).highHook = nil;
- }
-